package com.yisu.expressway.customService;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;

import com.umeng.socialize.utils.Log;
import com.yisu.expressway.R;
import com.yisu.expressway.activity.BaseActivity;
import com.yisu.expressway.databinding.ActivityShowTextContentBinding;
import com.yisu.expressway.utils.StringUtil;

public class ShowTextContentActivity extends BaseActivity {

    private final static String PAGE_TITLE = "page_title";
    private final static String PAGE_CONTENT = "page_content";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityShowTextContentBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_show_text_content);
        initView(getIntent(),binding);
    }

    public static void launch(Context context,String title,String content){
        Intent intent = new Intent(context,ShowTextContentActivity.class);
        intent.putExtra(PAGE_TITLE,title);
        intent.putExtra(PAGE_CONTENT,content);

        context.startActivity(intent);
    }

    private void initView(Intent intent,ActivityShowTextContentBinding binding){
        String title = intent.getStringExtra(PAGE_TITLE);
        if(StringUtil.isNullOrEmpty(title)){
            setTitle(R.string.text_content_title);
        }else {
            setTitle(title);
        }

        String content = intent.getStringExtra(PAGE_CONTENT);
        if(!StringUtil.isNullOrEmpty(content)) {
            binding.setPageContent(Html.fromHtml(content).toString());
        }
    }
}
